﻿using Microsoft.AspNetCore.Mvc;
using MVC_System.DTO.WXTWorkerHour;
using Newtonsoft.Json;
using WMS_MAV;

namespace MVC_System.Controllers
{
    public class WorkerHourController : Controller
    {
        private readonly IConfiguration _configuration;

        public WorkerHourController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        /// <summary>
        /// 工人工时显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult WorkerHourShow()
        {
            return View();
        }
        /// <summary>
        /// 工人工时显示
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<ActionResult> GetShowWorkerHour(WorkerHourShowDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "WXT/api/WorkeHour/WorkeHourShow?pageIndex=" + dto.pageIndex + "&pageSize=" + dto.pageSize + "&workerHourNumbering=" + dto.workerHourNumbering + "&workerHourState="+dto.workerHourState;
            var respomse = await client.GetAsync(url);
            return Json(respomse);
        }
        /// <summary>
        /// 工人工时添加
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ActionResult> GetAddWorkerHour(WorkerHourAddDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "WXT/api/WorkeHour/WorkeHourAdd";
            var respomse = await client.PostAsync(url,dto.Data);
            return Json(respomse);
        }
        /// <summary>
        /// 工人工时删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ActionResult> GetDeleteWorkerHour(WorkerHourDeleteDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "WXT/api/WorkeHour/WorkeHourDelete";
            var response = await client.PostAsync(url,dto.Data);
            return Json(response);
        }
        /// <summary>
        /// 工人工时反填
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        /// 
        [HttpGet]
        public async Task<ActionResult> GetBackFillWorkerHour(WorkerHourBackFillDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "WXT/api/WorkeHour/WorkeHourBackFill?workerHourId="+dto.workerHourId;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 工人工时修改
        /// </summary>
        /// <param name="obj1"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        /// 
        [HttpPost]
        public async Task<ActionResult> GetUpdateWorkerHour(WorkerHourUpdateDTO obj1,string token)
        {
            HttpClientWrapper client = new HttpClientWrapper(token);
            string url = _configuration["Url"] + "WXT/api/WorkeHour/WorkeHourUpdate";
            string list = JsonConvert.SerializeObject(obj1);
            var response = await client.PostAsync(url, list);
            return Json(response);
        }
    }
}
